﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using Hip.Define_Test.Properties;

namespace Hip.Define_Test {
	/// <summary>
	/// Interaction logic for TestModelView.xaml
	/// </summary>
	public partial class TestModelView: UserControl, INotifyPropertyChanged {
		protected virtual void Changed( string propertyName ) {
			PropertyChangedEventHandler handler = PropertyChanged;
			if ( handler != null ) {
				handler( this, new PropertyChangedEventArgs( propertyName ) );
			}
		}

		public new TestModel DataContext {
			get { return (TestModel)base.DataContext; }
			set { base.DataContext = value; }
		}

		private bool _bigness;
		public bool Bigness {
			get {
				return _bigness;
			}
			set {
				if ( _bigness != value ) {
					_bigness = value;
					Changed( "Bigness" );
				}
			}
		}

		[DependsOn( "context.Awesome" )]
		public string Status {
			get {
				//return "lame. uber-lame.";
				return DataContext.Awesome ? "Awesome!" : "Not so awesome, but generally spiffy.";
			}
		}

		public TestModelView() {
			InitializeComponent();
		}

		static TestModelView() {
			LinkExtension.AddTarget( "settings", Settings.Default );
		}

		[DependsOn( "context.Name" )]
		[DependsOn( "settings.AllCaps" )]
		private string Name_Text() {
			string name = DataContext.Name;
			return Settings.Default.AllCaps ? name.ToUpper() : name;
		}
		private string SetName {
			set {
				DataContext.Name = value;
			}
		}

		[DependsOn( "this.Bigness" )]
		private double GetTitleSize() {
			if ( Bigness )
				return 24;
			else
				return 12;
		}

		public event PropertyChangedEventHandler PropertyChanged;

		private void ToggleAwesomeness_Button( object sender, RoutedEventArgs e ) {
			DataContext.Awesome = !DataContext.Awesome;
		}
	}

	public class AddressConverter: IValueConverter {
		public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture ) {
			return ( (string)value ).ToUpper();
		}

		public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture ) {
			throw new NotImplementedException();
		}
	}

}
